/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:com.cesgroup.zw.spring.boot.echarts.graph</p>
 * <p>File:SimpleGraphParam.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 Jun 6, 2019 2:51:22 PM
 */
package com.cesgroup.zw.spring.boot.library.echarts.graph.simple;

import java.util.ArrayList;
import java.util.List;

import com.cesgroup.zw.spring.boot.charts.model.IChartsParam;
import com.cesgroup.zw.spring.boot.charts.model.IComponent;
import com.cesgroup.zw.spring.boot.echarts.component.series.Graph;
import com.cesgroup.zw.spring.boot.echarts.model.dataset.GraphDataset;
import com.cesgroup.zw.spring.boot.echarts.model.graph.GraphData;
import com.cesgroup.zw.spring.boot.echarts.model.graph.GraphLink;
import com.cesgroup.zw.spring.boot.echarts.model.series.Category;

import lombok.Builder;
import lombok.Data;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date Jun 6, 2019 2:51:22 PM
 * @version 1.0.2019
 */
@Data @Builder @SuppressWarnings("serial")
public class SimpleGraphParam implements IChartsParam<SimpleGraphSeries, GraphDataset[]> {

	private String name;
	
	private Category[] categories;
	
	private GraphDataset[] dataset;

	@Override
	public IComponent[] getSeries() {
		Graph graph = new SimpleGraphSeries(this);
		setOptions(graph, dataset);
		return new Graph[] {graph};
	}
	
	// 设置数据集（根据数据集生成“data”及“link”配置）
	public void setOptions(final Graph graph, final GraphDataset[] dataset) {
		List<GraphData> datas = new ArrayList<>();
		List<GraphLink> links = new ArrayList<>();

		for (GraphDataset data : dataset) {
			datas.add(data.getData());
			datas.addAll(data.getNodes());
			links.addAll(data.getLinks());
		}

		graph.setData(datas.toArray());
		graph.setLinks(links.toArray(new GraphLink[] {}));
	}
}
